<?
require ("imdbsearch.class.php");

$temp = explode(":",trim($argv[1]));
$temp = $temp[count($temp)-2];
$temp = explode("(",$temp);
$name = trim($temp[0]);

$h = fopen("/tmp/debug.log","w");
fwrite($h, print_r($argv,1));
exit;

$search = new imdbsearch();
$search->setsearchname ($name);

$results = $search->results();

foreach ($results as $res) {
	if(strtolower($res->title()) == strtolower($name)){
//		echo $res->imdbid();


		$movie = new imdb ($res->imdbid());
		$movieid = $res->imdbid();

		$movie->setid ($movieid);
		$cols = $movie->colors ();
		$sound = $movie->sound ();
		$country = $movie->country ();

		if(!is_array($cols)){ $cols = array($cols); }
		if(!is_array($akas)){ $akas = array($akas); }
		if(!is_array($country)){ $country = array($country); }
		if(!is_array($sound)){ $sound = array($sound); }

//		echo $movie->title()."<br />";
?>
<media type="Movie">
	<title><?php echo $movie->title(); ?></title>
	<description><?php $plot = $movie->plot (); echo preg_replace("/\<i\>.+?Written.*/s","",str_replace("\n","",$plot[0])); ?></description>
<?php
		$certs = $movie->mpaa();
		if(isset($certs["Belgium"])){ echo '	<rating>'.$certs["Belgium"].' (Belgium)</rating>'."\n"; }
		elseif(isset($certs["USA"])){ echo '	<rating>'.$certs["USA"].'</rating>'."\n"; }
?>
	<starRating><?php echo round($movie->rating()/2); ?></starRating>
	<published><?php echo $movie->year(); ?>-01-01</published>
	<genres>
<?php
		$gen = $movie->genres ();
		$setgenres = array();
		$i=0;
		foreach($gen as $genre){
			if(in_array($genre, $setgenres)){ continue; }
			echo '		<genre'.(($i==0)?' primary="true"':'').'>'.$genre.'</genre>'."\n";
			array_push($setgenres, $genre);
			$i++;
		}
?>
	</genres>
	<cast>
<?php
		$cast = $movie->cast();
		foreach($cast as $member){
			echo '		<name>'.$member["name"].'</name>'."\n";
		}
?>
	</cast>
	<producers>
<?php
		$cast = $movie->producer();
		foreach($cast as $member){
			echo '		<name>'.$member["name"].'</name>'."\n";
		}
?>
	</producers>
	<directors>
<?php
		$cast = $movie->director();
		foreach($cast as $member){
			echo '		<name>'.$member["name"].'</name>'."\n";
		}
?>
	</directors>
	<authors>
<?php
		$cast = $movie->writing();
		foreach($cast as $member){
			echo '		<name>'.$member["name"].'</name>'."\n";
		}
?>
	</authors>
</media>
<?php
	exit;
	}
}

?>
